package info.openlvb.openface.client.handler;

import info.openlvb.openface.client.base.machine.ListMachinePanel;
import info.openlvb.openface.client.base.machine.MachineWindow;
import info.openlvb.openface.client.service.LdapService;
import info.openlvb.openface.client.service.LdapServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.MessageBox;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

public class DeleteMachineListener extends ButtonListenerAdapter {

	private MachineWindow machineWindow;
	//private ListMachinePanel listMachinePanel;
	private String uid;
	private final LdapServiceAsync ldapService = GWT.create(LdapService.class);
	
	public DeleteMachineListener(MachineWindow machineWindow,
			ListMachinePanel listMachinePanel, String uid) {
		this.machineWindow = machineWindow;
		//this.listMachinePanel = listMachinePanel;
		this.uid = uid;
	}
	
	public void onClick(Button button, EventObject e) {
		
		ldapService.deleteMachine(uid, new AsyncCallback<Void>() {
			public void onSuccess(Void result) {
				MessageBox.alert("ordinateur supprimé");
				machineWindow.hide();
			}
			public void onFailure(Throwable caught) {
				MessageBox.alert("problème de backend");
			}
		});
	}
}
